package com.xpj;

/**
 * 分析i++字节码用
 */
public class ClassAnalyse {

    public static void main(String[] args) throws InterruptedException {
        ClassAnalyse classAnalyse = new ClassAnalyse();
        Thread t1 = new Thread(classAnalyse::increments);
        Thread t2 = new Thread(classAnalyse::increments);
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(classAnalyse.sum);

    }

    public void increments() {
        for (int i = 0; i < 10000; i++) {
            increment();
        }
    }

    public /*synchronized*/ void increment() {
        this.sum = sum + 1;
    }

    private int sum;
}
